<?php if (!defined('SERVER_ROOT')) exit('No direct script access allowed');

class hoso_Controller extends Controller {
    function __construct(){
        parent::__construct('tracuu', 'hoso');
        $this->check_login();
        $this->view->template->menu_html =$this->CREATE_MENU();
        $this->view->template->nhacviec_html =$this->CREATE_NHAC_VIEC();
        $this->CHECK_QUYEN('tracuu', 'hoso');
    }

    function main(){
        $this->dsp_all_hoso();
    }
    private function _save_filter_thutuc(){
        $v_TYPE_filter = $this->get_post_var('hdn_TYPE_filter');
        $v_TEN_TAT_filter = $this->get_post_var('txt_TEN_TAT_filter');
        $v_MA_THU_TUC_filter = $this->get_post_var('cbx_MA_THU_TUC_filter');
        $v_TRANG_THAI_HO_SO_filter = $this->get_post_var('hdn_TRANG_THAI_HO_SO_filter');
        $v_SO_HO_SO = $this->get_post_var('txt_SO_HO_SO');
        $v_SO_BIEN_NHAN = $this->get_post_var('txt_SO_BIEN_NHAN');
        $v_TEN_CONG_DAN = $this->get_post_var('txt_TEN_CONG_DAN');
        $v_CMND_CONG_DAN = $this->get_post_var('txt_CMND_CONG_DAN');
        $v_DI_DONG_CONG_DAN = $this->get_post_var('txt_DI_DONG_CONG_DAN');
        $v_DIA_CHI_CONG_DAN = $this->get_post_var('txt_DIA_CHI_CONG_DAN');
        $v_VE_VIEC = $this->get_post_var('txt_VE_VIEC');
        $v_MA_DON_VI_TIEP_NHAN = $this->get_post_var('cbx_MA_DON_VI_TIEP_NHAN');
        $v_NHAN_TU_NGAY = $this->get_post_var('txt_NHAN_TU_NGAY');
        $v_NHAN_DEN_NGAY = $this->get_post_var('txt_NHAN_DEN_NGAY');
        $v_HEN_TRA_TU_NGAY = $this->get_post_var('txt_HEN_TRA_TU_NGAY');
        $v_HEN_TRA_DEN_NGAY = $this->get_post_var('txt_HEN_TRA_DEN_NGAY');
        $v_NAM = $this->get_post_var('cbx_NAM');
        $v_MA_DON_VI_XU_LY = $this->get_post_var('cbx_MA_DON_VI_XU_LY');

        if($v_MA_DON_VI_XU_LY == '' && $v_TYPE_filter==''){
           $v_MA_DON_VI_XU_LY = 'UBND_HUYEN_CHO_GAO';
        }
        if($v_TYPE_filter == ''){
           $v_TYPE_filter = 'TRANG_THAI_HO_SO';// mac dinh search theo trang thai
        }
        if($v_MA_THU_TUC_filter == ''){
           $v_MA_THU_TUC_filter = 0;   // mac dinh search tat ca
        }
        if($v_TRANG_THAI_HO_SO_filter == ''){
           $v_TRANG_THAI_HO_SO_filter = 0;  //mac dinh lay vua tiep nhan
        }
        if($v_NAM == ''){
           $v_NAM = date('Y');
        }
        return array(
            'hdn_TYPE_filter'   => $v_TYPE_filter,
            'txt_TEN_TAT_filter'=> $v_TEN_TAT_filter,
            'cbx_MA_THU_TUC_filter'=> $v_MA_THU_TUC_filter,
            'hdn_TRANG_THAI_HO_SO_filter'=> $v_TRANG_THAI_HO_SO_filter,
            'txt_SO_HO_SO'=> $v_SO_HO_SO,
            'txt_SO_BIEN_NHAN'=> $v_SO_BIEN_NHAN,
            'txt_TEN_CONG_DAN'=> $v_TEN_CONG_DAN,
            'txt_CMND_CONG_DAN'=> $v_CMND_CONG_DAN,
            'txt_DI_DONG_CONG_DAN'=> $v_DI_DONG_CONG_DAN,
            'txt_DIA_CHI_CONG_DAN'=> $v_DIA_CHI_CONG_DAN,
            'txt_VE_VIEC'=> $v_VE_VIEC,
            'cbx_MA_DON_VI_TIEP_NHAN'=> $v_MA_DON_VI_TIEP_NHAN,
            'txt_NHAN_TU_NGAY'=> $v_NHAN_TU_NGAY,
            'txt_NHAN_DEN_NGAY'=> $v_NHAN_DEN_NGAY,
            'txt_HEN_TRA_TU_NGAY'=> $v_HEN_TRA_TU_NGAY,
            'txt_HEN_TRA_DEN_NGAY'=> $v_HEN_TRA_DEN_NGAY,
            'cbx_NAM'=> $v_NAM,
            'cbx_MA_DON_VI_XU_LY'=> $v_MA_DON_VI_XU_LY,
        );
    }
    /************************** FORM dsp_all_tracuu**********************/
    function dsp_all_hoso(){
        $arr_filter = $this->_save_filter_thutuc();
        $VIEW_DATA['arr_filter'] = $arr_filter;
        $VIEW_DATA['arr_all_thutuc_dathuchien'] = $this->model->SELECT_THU_TUC_DA_THUC_HIEN($arr_filter);
        $VIEW_DATA['arr_single_thutuc']    = $this->model->SELECT_THU_TUC_DETAIL_BY_TYPE($arr_filter);
        //arr_single_thutuc de hien thi vo cai text txt_TEN_TAT_filter
        $VIEW_DATA['arr_menu_search']    = $this->model->DV_SELECT_MENU_SEARCH($arr_filter);
        $VIEW_DATA['arr_all_donvi_xuly']    = $this->model->SELECT_DONVI_tatca();
        // lay cac don vi cua mot cua xa
        // code cung trong db la : MA_LOAI_DON_VI LIKE 'BO_PHAN_TN_VA_TKQ_CAP_XA'
        $VIEW_DATA['arr_all_donvi_motcuaxa']    = $this->model->SELECT_DONVI_motcuaxa();
        if ($arr_filter['hdn_TRANG_THAI_HO_SO_filter'] == 12){
            $VIEW_DATA['arr_all_hoso']= $this->model->DV_SELECT_HS_SEARCH_CHAM_TD($arr_filter);
        }else if($arr_filter['hdn_TRANG_THAI_HO_SO_filter'] == 13){
            $VIEW_DATA['arr_all_hoso']= $this->model->DV_SELECT_HS_SEARCH_TKQ_TH($arr_filter);
        }else if($arr_filter['hdn_TRANG_THAI_HO_SO_filter'] == 14){
            $VIEW_DATA['arr_all_hoso']= $this->model->DV_SELECT_HS_SEARCH_TKQ_QH($arr_filter);
        }else{
            $VIEW_DATA['arr_all_hoso']= $this->model->DV_SELECT_HS_SEARCH($arr_filter);
        }
        $this->view->render('dsp_all_hoso',$VIEW_DATA);
    }
    /************************** FORM dsp_single_hoso**********************/
    public function dsp_single_hoso(){
         $v_m = trim(get_request_var('m'));
        $CMND_CONG_DAN = $this->get_post_var('txt_CMND_CONG_DAN');
        $VIEW_DATA['var_CMND_CONG_DAN'] = $CMND_CONG_DAN;
        $VIEW_DATA['arr_single_hoso'] = $this->model->qry_single_hoso($v_m);
        $VIEW_DATA['arr_all_filehoso'] = $this->model->qry_all_filehoso($v_m);
        $VIEW_DATA['arr_all_giayto'] = $this->model->qry_all_giayto_byhoso($v_m);
        $this->view->render('dsp_single_hoso', $VIEW_DATA);

    }
    /************************** FORM dsp_all_qths**********************/
    public function dsp_qths(){
        $MA_HO_SO = trim(get_request_var('m'));
        $SO_HO_SO = trim(get_request_var('s'));
        $VIEW_DATA['var_sohoso'] = $SO_HO_SO;
        $VIEW_DATA['arr_BUOC_HS_BY_MHS'] = $this->model->SELECT_BUOC_HS_BY_MHS_TRACUU($MA_HO_SO) ;
        $this->view->render('dsp_qths', $VIEW_DATA);
    }
    public function dsp_canbo_of_tcm($MA_TO_CHUYEN_MON){
        $MA_TO_CHUYEN_MON = trim(get_request_var('matochuyenmon'));
        $MA_CONG_VIEC_HO_SO = trim(get_request_var('macongviechoso'));
        $VIEW_DATA['arr_all_canbo'] = $this->model->SELECT_CAN_BO_CUA_CVHS($MA_TO_CHUYEN_MON,$MA_CONG_VIEC_HO_SO) ;
        $this->view->render('dsp_canbo_of_tcm', $VIEW_DATA);
    }
     public function dsp_canbo_of_lnnsd2($MA_TO_CHUYEN_MON){
        $MA_LOAI_NHOM_NSD = trim(get_request_var('malnnsd'));
        $MA_HO_SO= trim(get_request_var('mahoso'));
        $VIEW_DATA['arr_all_canbo'] = $this->model->SELECT_CAN_BO_CUA_LOAI_NNSD2($MA_LOAI_NHOM_NSD,$MA_HO_SO) ;
        $this->view->render('dsp_canbo_of_lnnsd2', $VIEW_DATA);
    }
}